/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.j4sc.submission.manager;

import com.googlecode.j4sc.submission.SubmissionReference;

/**
 * The ProgressiveRetrievalStrategy when set as the {@link RetrievalStrategy}
 * for the {@link SubmissionManager} allows retrieval of a
 * {@link SubmissionReference} in a progressive manner starting at one minute.
 * <p>
 * After each attempt, the period is doubled upto a max attempts set upon
 * construction e.g the second retrieval is allowed after one minute, then two,
 * four, eight and so on until max attempts has been reached.
 * <p>
 * The idea behind progressive periods is that the more retrieval attempts
 * required for a {@link SubmissionReference}, the more longer it is going to
 * take either because the audio is longer and thus will require more time to
 * convert or it is more difficult to convert due to quality or ambiguities.
 * 
 * @author Raj Patel, Dariusz Lorenc
 */
public class ProgressiveRetrievalStrategy extends BasicRetrievalStrategy {

    /**
     * Construct a new instance
     * 
     * @param maxAttempts
     *            the maximum number of retrieval attempts for a
     *            {@link SubmissionReference}, must be at least 1
     */
    public ProgressiveRetrievalStrategy(int maxAttempts) {
        super(maxAttempts);
    }

    ProgressiveRetrievalStrategy(int pollingInterval, int maxAttempts) {
        super(pollingInterval, maxAttempts);
    }

    /*
     * (non-Javadoc)
     * 
     * @seecom.googlecode.j4sc.submission.manager.RetrievalStrategy#
     * isSubmissionDueForRetrieval
     * (com.googlecode.j4sc.submission.SubmissionReference)
     */
    @Override
    public boolean isDueForRetrieval(SubmissionReference reference) throws ExpiredSubmissionReferenceException {
        return isDueForRetrieval(reference, true);
    }
}
